<?php
session_start();
include '../model/db.php'; //连接数据库
//判断是否表单提交

if($_POST['submit']=='提交'){

    //接收数据
//    var_dump($_POST);
    $arr=$_POST; //接收到了 文本框的数据

    unset($arr['submit']); //删除 submit 字段

    //如果密码为空就不修改
    if(empty($arr['pass'])){
        unset($arr['pass']);
    }else{
        $arr['pass']=md5($arr['pass']);
    }

    /**接收文件**/
    include '../model/fn.php';

    if($_FILES['tx']['size']>0){
        $arr['tx']=upd_file($_FILES['tx'],'/public/admin/img/wset');
    }
    if($_FILES['w_logo']['size']>0){
        $arr['w_logo']=upd_file($_FILES['w_logo'],'/public/admin/img/wset');
    }
    if($_FILES['w_banner']['size']>0){
        $arr['w_banner']=upd_file($_FILES['w_banner'],'/public/admin/img/wset');
    }

    //修改数据库

    $id=db_upd('bl_user',$arr,'id='.$_SESSION['admin']['id']);

    if($id){
        echo "<script>alert('修改成功！');location.href='./wset.php';</script>";
    }else{
        echo "<script>alert('修改失败！');location.href='./wset.php';</script>";
    }

}

//查询数据，显示默认值
$sql="select * from bl_user where id = '{$_SESSION['admin']['id']}'";
$arr=db_sel($sql); //得到数据
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>后台 管理中心</title>
<meta name="robots" content="noindex, nofollow">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../public/admin/styles/general.css" rel="stylesheet" type="text/css" />
<link href="../public/admin/styles/main.css" rel="stylesheet" type="text/css" />
</head>
<body>

<h1>
<span class="action-span1"><a href="#">后台 管理中心</a> </span><span id="search_id" class="action-span1"></span>
<div style="clear:both"></div>
</h1>
<ul id="lilist" style="padding:0; margin: 0; list-style-type:none; color: #CC0000;">
  </ul>
<ul style="padding:0; margin: 0; list-style-type:none; color: #CC0000;">
</ul>

<div class="list-div">
    <table cellspacing='1' cellpadding='3'>
        <form action="./wset.php" method="post" enctype="multipart/form-data">
            <tr>
                <td width="20%">管理员账号: <b><?php echo $_SESSION['admin']['user']?></b> </td>
                <td width="30%">密码：<input type="text" placeholder="不填代表不修改" name="pass"></td>
                <td width="20%">昵称：
                    <input type="text" name="nickname" value="<?php echo $arr['nickname']?>">
                </td>
                <td width="20%">头像：
                    <input type="file" name="tx">
                    <img src="<?php echo $arr['tx']?>" style="width: 50px" alt="没有头像">
                </td>
            </tr>
            <tr>
                <td width="20%">网站logo:
                    <input type="file" name="w_logo">
                    <img src="<?php echo $arr['w_logo']?>" style="width: 50px" alt="没有logo">
                </td>
                <td width="30%">网站banner：
                    <input type="file" name="w_banner" >
                    <img src="<?php echo $arr['w_banner']?>" style="width: 50px" alt="没有banner">
                </td>
                <td width="20%">网站描述：  <input type="text" name="w_msg" value="<?php echo $arr['w_msg']?>"></td>
                <td width="20%">网站title： <input type="text" name="w_title" value="<?php echo $arr['w_title']?>"> </td>
            </tr>
            <tr>
                <td colspan="4" style="text-align: center">
                    <input type="submit" name="submit" value="提交"></td>
            </tr>
        </form>
    </table>
</div>


<div id="footer">
    2017-2200, 海生学院，并保留所有权利。</div>

</body>
</html>